Skip to content

fix(libkernel): fail lseek on a pipe with ESPIPE on Windows - #4672

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
milescoviello:carry/lseek-pipe-windows-4670
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
milescoviello:carry/lseek-pipe-windows-4670

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #4670. Carries @DavidSamir's fix branch from that issue (DavidSamir:fix/libkernel-lseek-pipe-windows, 32f49a97), keeping the commit and its authorship; it is cherry-picked onto current main, with the declaration conflict #4536 left in GuestFilesystem.cpp resolved by keeping both.

On Windows, lseek and sceKernelLseek succeeded on a pipe and returned a position, and with SEEK_END the number of bytes waiting in it, because NativeLseek calls _lseeki64 and Windows accepts a position on a pipe handle. FreeBSD's lseek(2) fails with ESPIPE when the descriptor "is associated with a pipe, socket, or FIFO", and the Linux build already does. Windows NativeLseek now makes the same _lseeki64 call, so a closed or invalid descriptor fails as before, and then returns ESPIPE when the handle's type is FILE_TYPE_PIPE. Linux is unchanged.

guest_filesystem checks both ends of a pipe: lseek fails with errno 29 and sceKernelLseek returns 0x8002001D for SEEK_SET, SEEK_CUR and SEEK_END, the bytes written before are read back unchanged, and after close lseek fails with errno 9.

Tested

  • From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: with main's Open.cpp the new checks fail and with the fix guest_filesystem passes 5/5; a 97-operation file probe differs in one line, lseek on a pipe; eleven catalog titles end the same way with both sets of libraries; full ctest 973/973. About 0.1 µs is added to each seek by the GetFileType call.
  • Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, rebased onto main 9df7746 after fix(libkernel): keep sceKernelDebugOutText off a redirected guest stderr #4536 (which added a declaration next to this one in GuestFilesystem.cpp; both are kept). guest_filesystem, guest_kernel_fcntl, guest_dup and guest_poll pass, and all 310 guest_* tests pass. The new checks also pass with main's Open.cpp, as expected since only the Windows path changes. I could not run Windows myself.
  • tools/check_conventions.py --base upstream/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on the PR merged onto current main: scoped build and ctest (147 tests, guest_filesystem included) pass; no conflicts with #4973 or #4992. The change is Windows-only, so Linux is unchanged. ESPIPE (29) matches the guest value used in Stdio.cpp. Windows behaviour is covered by the full Build; merging once it is green.

@adriadam10
adriadam10 merged commit c422b57 into boykopovar:main Oct 13, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: lseek on a pipe succeeds on Windows and reports a position and a size, where FreeBSD fails with ESPIPE; fix branch ready

3 participants